package com.metaverse.backend.web;

import com.metaverse.backend.service.StorageService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@AllArgsConstructor
@RestController
@RequestMapping("/upload")
public class FileUploadController extends BaseController{


    private StorageService storageService;

    /**
     * 上传操作
     * @return
     */
    @PostMapping("file")
    public String file(@RequestParam("file") MultipartFile multipartFile) throws Exception {
        String uploadName = multipartFile.getOriginalFilename();
        String fullPath = storageService.upload(StorageService.UploadType.DEFAULT_UPLOAD, uploadName, multipartFile.getInputStream());
        return fullPath;
    }


}
